import csv

import requests
from bs4 import BeautifulSoup
url = "http://hksclz.com/groceries/index"
resp = requests.get(url)
# print(resp.text)
page = BeautifulSoup(resp.text,"html.parser")#指定html解析器
hu = page.find("div",class_="box_out_form box_out_form2")
# print(hu)
f=open("菜价.csv",mode="w")
csvwriter = csv.writer(f)
trs = hu.find_all("tr")[1:]
for tr in trs:
    tds = tr.find_all("td")
    sj = tds[0].text    #.text表示拿到被标签标记的内容
    name = tds[1].text
    perice= tds[2].text
    csvwriter.writerow([sj,name,perice])
f.close()
print("over!")
#从bs对象中查找数据
#find(标签，属性=值)
#find_all


